﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Web.Http;
using wepoverkefni5.Models;
using System.Net;

namespace wepoverkefni5.Controllers
{
    /// <summary>
    /// API Controller for handling the functionality of creating a new playlist, which is implemented in a separate controller due to 
    /// complications in how to invoke to different post request´s with similar parameters
    /// </summary>
    public class playlist2Controller : ApiController
    {
        DataRepository m_rep = new DataRepository();

        /// <summary>
        /// Create a new playlist
        /// </summary>
        /// <param name="playlist">PlaylistModel represents the model containing the name of the playlist to be created</param>
        /// <returns>HttpResponseMessage response</returns>
        public HttpResponseMessage Post(PlaylistModel playlist)
        {
            //System.Diagnostics.Debug.WriteLine("Trying to create playlist!");
            if (playlist == null)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }
            Playlist list = new Playlist();
            list.PlaylistName = playlist.listName;
            m_rep.addNewPlaylist(list);
            HttpResponseMessage response = new HttpResponseMessage();
            response.StatusCode = HttpStatusCode.Created;
            return response;
        }
    }
}
